package com.xxkj.nmip.utils;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

/**
 * @ProjectName: ucoupon-android
 * @Package: cio.dcloud.base.utils
 * @ClassName: ToastUtils
 * Created by mf on 2019/12/11 14:54
 * @Description: 吐司工具类
 */
public class ToastUtils {

    /**
     * 常用-居中Toast（本项目使用）
     *
     * @param context
     * @param text
     */
    public static void showCenter(Context context, CharSequence text) {
        Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    public static void showCenterLongTime(Context context, CharSequence text) {
        Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 常用-居中Toast（本项目使用）
     *
     * @param context
     * @param text
     * @param duration
     */
    public static void showCenter(Context context, CharSequence text, int duration) {
        Toast toast = Toast.makeText(context, text, duration);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    public static void showCenter(Context context, int resId) {
        Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    public static void showCenter(Context context, int resId, int duration) {
        Toast toast = Toast.makeText(context, resId, duration);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 系统默认Toast
     *
     * @param context
     * @param text
     */
    public static void show(Context context, CharSequence text) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }

    /**
     * 系统默认Toast
     *
     * @param context
     * @param text
     * @param duration
     */
    public static void show(Context context, CharSequence text, int duration) {
        Toast toast = Toast.makeText(context, text, duration);
        toast.setGravity(duration, 0, 0);
        toast.show();
    }

}
